home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / obsolete / xmenu.pro < prev    next >
Text File  |  1997-07-08  |  7KB  |  208 lines

  1. ; $Id: xmenu.pro,v 1.2 1997/01/15 04:02:19 ali Exp $
  2. ;
  3. ; Copyright (c) 1991-1997, Research Systems, Inc.  All rights reserved.
  4. ;    Unauthorized reproduction prohibited.
  5. ;+
  6. ; NAME:
  7. ;    XMENU
  8. ;
  9. ; PURPOSE:
  10. ;    This procedure simplifies setting up widget menus. XMENU accepts a 
  11. ;    string array of menu labels, creates a widget base, and populates
  12. ;    the base with buttons containing the specified labels.
  13. ;
  14. ; CALLING SEQUENCE:
  15. ;    XMENU, Values [, Parent]
  16. ;
  17. ; INPUTS:
  18. ;    Values:    An array of labels for the butons (menu items).  
  19. ;        If VALUES is a string array, then it is a 1-D array of labels.
  20. ;        If it a byte array, it is a 3-D array of bitmaps, where
  21. ;        the 1st 2 dimensions are the width and height of each
  22. ;        bitmap.
  23. ;
  24. ;    Parent:    The widget ID of parent base widget.  If this argument is
  25. ;        omitted, the menu base is a top-level base.
  26. ;
  27. ; KEYWORDS:
  28. ;    BASE:    A named variable to recieve the widget ID of the created base.
  29. ;
  30. ;      BUTTONS:    A named variable to recieve the widget ID of the created
  31. ;        buttons. This return value is a longword array, with each
  32. ;        element matching the corresponding element in Values.
  33. ;
  34. ;    COLUMN: This keyword specifies that the buttons should be layed out 
  35. ;        in columns. The value specified gives the number of columns
  36. ;        desired.
  37. ;
  38. ;    EXCLUSIVE:    Set this keyword to make each menu selection an exclusive
  39. ;        button.  Exclusive buttons have both selected and unselected 
  40. ;        states and only one button at a time can be selected.
  41. ;
  42. ;    FONT:    A string containing the name of the font for the button labels.
  43. ;
  44. ;    FRAME:    If this keyword is specified, it represents the thickness (in
  45. ;        pixels) of the frame drawn around the base.  The default is
  46. ;        no frame.
  47. ;
  48. ; NONEXCLUSIVE:    Set this keyword to make each menu selection a non-exclusive
  49. ;        button.  Non-exclusive buttons have both selected and 
  50. ;        un-selected states.  More that one button can be selected at
  51. ;        one time.
  52. ;
  53. ;   NO_RELEASE:    Set this keyword to prevent the buttons from returning release
  54. ;        events.  Normally, buttons return both selection and release
  55. ;        events.
  56. ;
  57. ;    ROW:    This keyword specifies that the buttons should be layed out 
  58. ;        in rows.  The value specified gives the number of rows desired.
  59. ;
  60. ;    SCROLL:    Set this keyword to give the base scrollbars to allow a large 
  61. ;        number of buttons to be viewed in a small region.
  62. ;
  63. ;    SPACE:    The space, in pixels, to be left around the edges of the base.
  64. ;
  65. ;    TITLE:    If PARENT is not specified, TITLE specifies the MENU title.
  66. ;        If PARENT is specified, a framed base is created and a
  67. ;        label with the value TITLE is added before the menu. 
  68. ;
  69. ;    XPAD:    The horizontal space, in pixels, to be left between the 
  70. ;        buttons.
  71. ;
  72. ;    YPAD:    The vertical space, in pixels, to be left between the buttons.
  73. ;
  74. ;    UVALUE:    An array of user values to be set into the UVALUE of the
  75. ;        buttons. This array must have the same number of elements
  76. ;        as VALUES.
  77. ;
  78. ;X_SCROLL_SIZE:    The width of the scrolling viewport.  This keyword implies 
  79. ;        SCROLL.
  80. ;
  81. ;Y_SCROLL_SIZE:    The height of the scrolling viewport.  This keyword
  82. ;        implies SCROLL.
  83. ;    
  84. ; OUTPUTS:
  85. ;    None.
  86. ;
  87. ; COMMON BLOCKS:
  88. ;    None.
  89. ;
  90. ; SIDE EFFECTS:
  91. ;    A widget base containing buttons is created, but not realized.
  92. ;
  93. ; EXAMPLE:
  94. ;    For an example of using XMENU to create menus see the "Non-Exclusive
  95. ;    Menu" and "Exclusive Menu" examples in the "Simple Widget Examples".
  96. ;    The simple widget examples menu can be seen by entering WEXMASTER at
  97. ;    the IDL prompt.
  98. ;
  99. ; MODIFICATION HISTORY:
  100. ;    16 January 1991, AB, RSI
  101. ;
  102. ;    5 September 1991, SMR, RSI   Fixed bug where titles were ignored when
  103. ;                     no base specified.
  104. ;
  105. ;    21 January 1992, ACY, RSI    Added FONT keyword.
  106. ;-
  107. PRO XMENU, VALUES, PARENT, BASE=BASE, BUTTONS=BUTTONS, COLUMN=COLUMN, $
  108.     EXCLUSIVE=EXCLUSIVE, FONT=FONT, FRAME=FRAME, $
  109.     NONEXCLUSIVE=NONEXCLUSIVE, ROW=ROW, SCROLL=SCROLL, SPACE=SPACE, $
  110.     XPAD=XPAD, YPAD=YPAD, UVALUE=UVALUE, X_SCROLL_SIZE=X_SCROLL_SIZE, $
  111.     Y_SCROLL_SIZE=Y_SCROLL_SIZE, TITLE = TITLE, NO_RELEASE = NO_RELEASE
  112.  
  113.   ; Error check the plain arguments
  114.   s = size(parent)
  115.   if (s(s(0) + 1) eq 0) then begin
  116.     ; No parent is specified.
  117.     parent = 0
  118.     if (not keyword_set(TITLE)) then TITLE = 'Menu'
  119.   endif else begin
  120.     if (s(0) ne 0) then message, 'PARENT must be a scalar value."
  121.     if (s(1) ne 3) then message, 'PARENT must be a long integer."
  122.   endelse
  123.   s = size(VALUES)
  124.   value_type = s(s(0) + 1)
  125.   if ((value_type ne 1) and (value_type ne 7)) then $
  126.     message, 'VALUES must be a string vector or 3-D byte array.`
  127.   if (value_type eq 1) then begin
  128.     if (s(0) ne 3) then message, 'Type Byte VALUES must be 3-D'
  129.     n_buttons = s(3)
  130.   endif else begin
  131.     n_buttons = n_elements(VALUES)
  132.   endelse
  133.  
  134.   ; Sort out the keywords
  135.   if ((not keyword_set(row)) and (not keyword_set(column))) then column=1
  136.   if (not keyword_set(COLUMN)) then COLUMN=0
  137.   if (not keyword_set(FONT)) then FONT = ''
  138.   if (not keyword_set(ROW)) then ROW=0
  139.   if (not keyword_set(EXCLUSIVE)) then EXCLUSIVE=0
  140.   if (not keyword_set(NONEXCLUSIVE)) then NONEXCLUSIVE=0
  141.   if (keyword_set(scroll) or keyword_set(x_scroll_size) or $
  142.       keyword_set(y_scroll_size)) then begin
  143.     scroll = 1;
  144.     if (not keyword_set(x_scroll_size)) then x_scroll_size=0
  145.     if (not keyword_set(y_scroll_size)) then y_scroll_size=0
  146.   endif else begin
  147.     scroll=0
  148.   endelse
  149.   if (not keyword_set(frame)) then frame = 0
  150.   if (not keyword_set(space)) then space = 0
  151.   if (not keyword_set(xpad)) then xpad = 0
  152.   if (not keyword_set(ypad)) then ypad = 0
  153.   if (not keyword_set(uvalue)) then begin
  154.     uvalue=lindgen(n_buttons)
  155.   endif else begin
  156.     s = size(uvalue)
  157.     if (s(s(0) + 2) ne n_buttons) then $
  158.       message, 'UVALUE must have the same number of elements as VALUES'
  159.   endelse
  160.  
  161.   ; Create the base
  162.   if (parent eq 0) then begin
  163.     if (scroll) then $
  164.       base = widget_base(COLUMN=COLUMN, EXCLUSIVE=EXCLUSIVE, $
  165.       FRAME=FRAME, NONEXCLUSIVE=NONEXCLUSIVE, ROW=ROW, SCROLL=SCROLL, $
  166.       SPACE=SPACE, XPAD=XPAD, YPAD=YPAD, X_SCROLL_SIZE=X_SCROLL_SIZE, $
  167.       Y_SCROLL_SIZE=Y_SCROLL_SIZE, TITLE = TITLE, $
  168.       X_SCROLL_INCR = 20, Y_SCROLL_INCR = 20) $
  169.     else $
  170.       base = widget_base(COLUMN=COLUMN, EXCLUSIVE=EXCLUSIVE, $
  171.       FRAME=FRAME, NONEXCLUSIVE=NONEXCLUSIVE, ROW=ROW, $
  172.       SPACE=SPACE, XPAD=XPAD, YPAD=YPAD, TITLE = TITLE)
  173.   endif else begin
  174.     if (KEYWORD_SET(TITLE)) THEN BEGIN
  175.       theparent = widget_base(parent, /COLUMN, /FRAME)
  176.       thelabel = widget_label(theparent, value = title)
  177.     ENDIF ELSE theparent = parent
  178.     if (scroll) then $
  179.       base = widget_base(theparent, COLUMN=COLUMN, EXCLUSIVE=EXCLUSIVE, $
  180.       FRAME=FRAME, NONEXCLUSIVE=NONEXCLUSIVE, ROW=ROW, SCROLL=SCROLL, $
  181.       SPACE=SPACE, XPAD=XPAD, YPAD=YPAD, X_SCROLL_SIZE=X_SCROLL_SIZE, $
  182.       Y_SCROLL_SIZE=Y_SCROLL_SIZE) $
  183.     else $
  184.       base = widget_base(theparent, COLUMN=COLUMN, EXCLUSIVE=EXCLUSIVE, $
  185.       FRAME=FRAME, NONEXCLUSIVE=NONEXCLUSIVE, ROW=ROW, $
  186.       SPACE=SPACE, XPAD=XPAD, YPAD=YPAD)
  187.   endelse
  188.  
  189.   ; Create the buttons
  190.   buttons = lindgen(n_buttons)
  191.   if (value_type eq 1) then begin
  192.     for i = 0, n_buttons-1 do $
  193.       buttons(i) = WIDGET_BUTTON(base, $
  194.         value=values(*, *, i), $
  195.         no_release = no_release, $
  196.         uvalue=uvalue(i), $
  197.         FONT = FONT)
  198.   endif else begin
  199.     for i = 0, n_buttons-1 do $
  200.       buttons(i) = WIDGET_BUTTON(base, $
  201.         value=values(i), $
  202.         no_release = no_release, $
  203.         uvalue=uvalue(i), $
  204.         FONT = FONT)
  205.   endelse
  206.  
  207. end
  208.